package com.ld.admin.controller.usercenter;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ld.admin.controller.AdminBasicController;
import com.ld.admin.model.usercenter.SysUserNoteModel;
import com.ld.admin.service.usercenter.SysUserNoteService;
import com.ld.shieldsb.annotation.duplicate.SubmitRequestIntercept;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.web.util.Web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * 用户便签/备忘录
 * 
 * @ClassName SysUserNoteController
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2019年07月02日 11:19:33
 *
 */
@Api(tags = "用户便签/备忘录")
@ConditionalOnProperty(prefix = "modules.sc.usercenter", name = "sysusernote.enable", havingValue = "true", matchIfMissing = true)
@Controller(value = "usercenterSysUserNoteController")
@RequestMapping("${shieldsb.adminPath}/usercenter/sysusernote")
public class SysUserNoteController extends AdminBasicController<SysUserNoteModel> {
    @Autowired
    protected SysUserNoteService sysUserNoteService;

    @ApiOperation(value = "首页", notes = "")
    @RequestMapping(path = "", method = RequestMethod.GET)
    public String index() {
        return "forward:" + adminPath + "/usercenter/sysusernote/toSearch"; // 跳转搜索页面
    }

    @ApiOperation(value = "到搜索页面", notes = "")
    @RequestMapping(path = "/toSearch", method = RequestMethod.GET)
    public String toSearch() {
        return "a/usercenter/sysusernote/sysusernote_search";
    }

    @ApiOperation(value = "搜索结果", notes = "")
    @RequestMapping(path = "/search")
    // 返回json格式
    @ResponseBody
    public Object search() {
        Result result = sysUserNoteService.getData(request);
        return Web.Response.resultWithData(result);
    }

    @ApiOperation(value = "添加/修改用户便签/备忘录", notes = "")
    @RequestMapping(path = "/addOrUpdate", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    @SubmitRequestIntercept(desp = "提交拦截验证", interval = 3)
    public Object addOrUpd(@Valid SysUserNoteModel model) {
        Result result = sysUserNoteService.addOrUpdate(model, model.getId() != null);
        return Web.Response.result(result);
    }

    @ApiOperation(value = "删除用户便签/备忘录", notes = "")
    @RequestMapping(path = "/del", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    public Object del() {
        long id = getLong("id");
        Result result = sysUserNoteService.remove(getModelClass(), id);
        return Web.Response.result(result);
    }

}